using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using IpBox;

namespace View
{
	/// <summary>
	/// Summary description for SetupView.
	/// </summary>
	public class SetupView : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ToolBar toolBar1;
		private PinkieControls.ButtonXP finishButton;
		private PinkieControls.ButtonXP cancelButton;
		private System.Windows.Forms.CheckBox allowUserCheckBox;
		private System.Windows.Forms.TextBox ipBox;
		private System.Windows.Forms.Label ipLabel;
		private System.Windows.Forms.RichTextBox richTextBox1;
		private System.Windows.Forms.RadioButton localButton;
		private System.Windows.Forms.RadioButton remoteButton;
		private System.Windows.Forms.PictureBox pictureBox1;
		private IpBox.IpBox ipBox1;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public SetupView()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			allowUserCheckBox.Visible = true;
			ipBox.Visible = false;
			ipBox1.Visible = false;
			ipLabel.Visible = false;
			localButton.Checked = true;


			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SetupView));
			this.toolBar1 = new System.Windows.Forms.ToolBar();
			this.finishButton = new PinkieControls.ButtonXP();
			this.cancelButton = new PinkieControls.ButtonXP();
			this.localButton = new System.Windows.Forms.RadioButton();
			this.remoteButton = new System.Windows.Forms.RadioButton();
			this.allowUserCheckBox = new System.Windows.Forms.CheckBox();
			this.ipBox = new System.Windows.Forms.TextBox();
			this.ipLabel = new System.Windows.Forms.Label();
			this.richTextBox1 = new System.Windows.Forms.RichTextBox();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.ipBox1 = new IpBox.IpBox();
			this.SuspendLayout();
			// 
			// toolBar1
			// 
			this.toolBar1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.toolBar1.DropDownArrows = true;
			this.toolBar1.Location = new System.Drawing.Point(0, 349);
			this.toolBar1.Name = "toolBar1";
			this.toolBar1.ShowToolTips = true;
			this.toolBar1.Size = new System.Drawing.Size(545, 42);
			this.toolBar1.TabIndex = 1;
			// 
			// finishButton
			// 
			this.finishButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.finishButton.DefaultScheme = true;
			this.finishButton.DialogResult = System.Windows.Forms.DialogResult.None;
			this.finishButton.Hint = "";
			this.finishButton.Location = new System.Drawing.Point(320, 360);
			this.finishButton.Name = "finishButton";
			this.finishButton.Scheme = PinkieControls.ButtonXP.Schemes.Silver;
			this.finishButton.Size = new System.Drawing.Size(104, 24);
			this.finishButton.TabIndex = 20;
			this.finishButton.Text = "Finish";
			this.finishButton.Click += new System.EventHandler(this.finishButton_Click);
			// 
			// cancelButton
			// 
			this.cancelButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)));
			this.cancelButton.DefaultScheme = true;
			this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.None;
			this.cancelButton.Hint = "";
			this.cancelButton.Location = new System.Drawing.Point(424, 360);
			this.cancelButton.Name = "cancelButton";
			this.cancelButton.Scheme = PinkieControls.ButtonXP.Schemes.Silver;
			this.cancelButton.Size = new System.Drawing.Size(104, 24);
			this.cancelButton.TabIndex = 21;
			this.cancelButton.Text = "Cancel";
			this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
			// 
			// localButton
			// 
			this.localButton.Location = new System.Drawing.Point(216, 232);
			this.localButton.Name = "localButton";
			this.localButton.Size = new System.Drawing.Size(232, 24);
			this.localButton.TabIndex = 22;
			this.localButton.Text = "Store my financial data in this computer";
			this.localButton.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
			// 
			// remoteButton
			// 
			this.remoteButton.Location = new System.Drawing.Point(216, 256);
			this.remoteButton.Name = "remoteButton";
			this.remoteButton.Size = new System.Drawing.Size(296, 24);
			this.remoteButton.TabIndex = 23;
			this.remoteButton.Text = "Access my financial data from an external computer";
			this.remoteButton.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
			// 
			// allowUserCheckBox
			// 
			this.allowUserCheckBox.Location = new System.Drawing.Point(216, 296);
			this.allowUserCheckBox.Name = "allowUserCheckBox";
			this.allowUserCheckBox.Size = new System.Drawing.Size(280, 24);
			this.allowUserCheckBox.TabIndex = 24;
			this.allowUserCheckBox.Text = "Allow other users to connect to this computer";
			// 
			// ipBox
			// 
			this.ipBox.Location = new System.Drawing.Point(288, 304);
			this.ipBox.Name = "ipBox";
			this.ipBox.Size = new System.Drawing.Size(232, 20);
			this.ipBox.TabIndex = 25;
			this.ipBox.Text = "0.0.0.0";
			this.ipBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Enter_KeyUp);
			// 
			// ipLabel
			// 
			this.ipLabel.Location = new System.Drawing.Point(216, 304);
			this.ipLabel.Name = "ipLabel";
			this.ipLabel.Size = new System.Drawing.Size(64, 23);
			this.ipLabel.TabIndex = 26;
			this.ipLabel.Text = "IP address:";
			// 
			// richTextBox1
			// 
			this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.richTextBox1.Location = new System.Drawing.Point(216, 56);
			this.richTextBox1.Name = "richTextBox1";
			this.richTextBox1.ReadOnly = true;
			this.richTextBox1.Size = new System.Drawing.Size(312, 168);
			this.richTextBox1.TabIndex = 27;
			this.richTextBox1.Text = @"This configuration will allow you to change the way Mizaniya are accessing your financial data.

Your data can either be stored locally or remotely. In local mode, you will have the option to run Mizaniya as a single user i.e. no users can connect to your computer. In remote mode, you will be asked to enter the IP address of the machine where you want to share your financial data.

Click Finish to update your settings or Cancel to exit the Configuration Wizard.";
			// 
			// pictureBox1
			// 
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(0, 0);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(560, 354);
			this.pictureBox1.TabIndex = 28;
			this.pictureBox1.TabStop = false;
			// 
			// ipBox1
			// 
			this.ipBox1.GetIPAddress = ((System.Net.IPAddress)(resources.GetObject("ipBox1.GetIPAddress")));
			this.ipBox1.Location = new System.Drawing.Point(287, 298);
			this.ipBox1.Name = "ipBox1";
			this.ipBox1.Size = new System.Drawing.Size(105, 23);
			this.ipBox1.TabIndex = 29;
			this.ipBox1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Enter_KeyUp);
			// 
			// SetupView
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.SystemColors.Window;
			this.ClientSize = new System.Drawing.Size(545, 391);
			this.Controls.Add(this.ipBox1);
			this.Controls.Add(this.richTextBox1);
			this.Controls.Add(this.ipLabel);
			this.Controls.Add(this.ipBox);
			this.Controls.Add(this.allowUserCheckBox);
			this.Controls.Add(this.remoteButton);
			this.Controls.Add(this.localButton);
			this.Controls.Add(this.cancelButton);
			this.Controls.Add(this.finishButton);
			this.Controls.Add(this.toolBar1);
			this.Controls.Add(this.pictureBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "SetupView";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Mizaniya Configuration";
			this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Enter_KeyUp);
			this.ResumeLayout(false);

		}
		#endregion

		private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
		{
			allowUserCheckBox.Visible = true;
			ipBox.Visible = false;
			ipBox1.Visible = false;
			ipLabel.Visible = false;
		}

		private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
		{
			//ipBox.Visible = true;
			ipBox1.Visible = true;
			ipLabel.Visible = true;
			allowUserCheckBox.Visible = false;
		}

		private void cancelButton_Click(object sender, System.EventArgs e)
		{
			this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.Dispose();
		}

		private void finishButton_Click(object sender, System.EventArgs e)
		{
			if(localButton.Checked)
			{
				MizClient.MizClient.ServerIP = "localhost";
				
				if(allowUserCheckBox.Checked && allowUserCheckBox.Visible)
					MizClient.MizClient.IsServiceAlwaysOn = true;
			}
			else if(remoteButton.Checked)
			{
				//MizClient.MizClient.ServerIP = ipBox.Text;
				MizClient.MizClient.ServerIP = ipBox1.GetIPAddress.ToString();
				MizClient.MizClient.IsServiceAlwaysOn = false;
			}
			this.DialogResult = System.Windows.Forms.DialogResult.OK;
		}

		private void Enter_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			// If enter is pressed
			if (e.KeyCode == Keys.Enter)
			{
				if(localButton.Checked)
				{
					MizClient.MizClient.ServerIP = "localhost";
				
					if(allowUserCheckBox.Checked && allowUserCheckBox.Visible)
						MizClient.MizClient.IsServiceAlwaysOn = true;
				}
				else if(remoteButton.Checked)
				{
					//MizClient.MizClient.ServerIP = ipBox.Text;
					MizClient.MizClient.ServerIP = ipBox1.GetIPAddress.ToString();
					MizClient.MizClient.IsServiceAlwaysOn = false;
				}
				this.DialogResult = System.Windows.Forms.DialogResult.OK;
			}
		}
	}
}
